package com.ruoyi.crayon.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.crayon.domain.CrayonBiz;
import com.ruoyi.crayon.service.ICrayonBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 业务组件Controller
 * 
 * @author ruoyi
 * @date 2023-10-11
 */
@RestController
@RequestMapping("/crayon/biz")
public class CrayonBizController extends BaseController
{
    @Autowired
    private ICrayonBizService crayonBizService;

    /**
     * 查询业务组件列表
     */
    @PreAuthorize("@ss.hasPermi('crayon:biz:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrayonBiz crayonBiz)
    {
        startPage();
        List<CrayonBiz> list = crayonBizService.selectCrayonBizList(crayonBiz);
        return getDataTable(list);
    }

    /**
     * 导出业务组件列表
     */
    @PreAuthorize("@ss.hasPermi('crayon:biz:export')")
    @Log(title = "业务组件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrayonBiz crayonBiz)
    {
        List<CrayonBiz> list = crayonBizService.selectCrayonBizList(crayonBiz);
        ExcelUtil<CrayonBiz> util = new ExcelUtil<CrayonBiz>(CrayonBiz.class);
        util.exportExcel(response, list, "业务组件数据");
    }

    /**
     * 获取业务组件详细信息
     */
    @PreAuthorize("@ss.hasPermi('crayon:biz:query')")
    @GetMapping(value = "/{bizId}")
    public AjaxResult getInfo(@PathVariable("bizId") Long bizId)
    {
        return success(crayonBizService.selectCrayonBizByBizId(bizId));
    }

    /**
     * 新增业务组件
     */
    @PreAuthorize("@ss.hasPermi('crayon:biz:add')")
    @Log(title = "业务组件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrayonBiz crayonBiz)
    {
        return toAjax(crayonBizService.insertCrayonBiz(crayonBiz));
    }

    /**
     * 修改业务组件
     */
    @PreAuthorize("@ss.hasPermi('crayon:biz:edit')")
    @Log(title = "业务组件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrayonBiz crayonBiz)
    {
        return toAjax(crayonBizService.updateCrayonBiz(crayonBiz));
    }

    /**
     * 删除业务组件
     */
    @PreAuthorize("@ss.hasPermi('crayon:biz:remove')")
    @Log(title = "业务组件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bizIds}")
    public AjaxResult remove(@PathVariable Long[] bizIds)
    {
        return toAjax(crayonBizService.deleteCrayonBizByBizIds(bizIds));
    }
}
